<template>
	<div class="library_cover_box" v-loading="loading">
		<el-card shadow="never" v-for="(item, index) in libCoverList" :key="index" :header="item.label">
			<cover-upload :type="item.category" :list="item.children"></cover-upload>
		</el-card>
	</div>
</template>

<script>
import lodash from 'lodash';
import { mapGetters } from 'vuex';
import coverUpload from './coverUpload';
import { getAttachList } from '@/api/global.js';
export default {
	components: { coverUpload },
	data() {
		return {
			loading: false,
			libCoverList: []
		};
	},
	computed: { ...mapGetters(['dictEnums']) },
	mounted() {
		this.queryLibCoverData();
	},
	methods: {
		//获取库封面
		async getLibCoverData() {
			let params = { page: 1, limit: 9999, type: 5 };
			let result = await getAttachList(params).then((res) => res.data);
			this.loading = false;
			if (result.code === '0') {
				let datas = !result.data ? [] : result.data;
				let treeArr = lodash.groupBy(datas, 'category');
				this.libCoverList = this.dictEnums['RESOURCES_CATEGORY'].map((n) => {
					return { label: n.msg, category: n.value, children: treeArr[n.value] || [] };
				});
			}
		},

		//查询封面数据
		async queryLibCoverData() {
			this.loading = true;
			this.getLibCoverData();
		}
	}
};
</script>
<style lang="scss" scoped>
.library_cover_box ::v-deep {
	flex: 1;
	padding: 0 16px 16px;
	overflow: hidden;
	overflow-y: auto;
	.el-card {
		margin-top: 16px;
	}
	.el-card__header {
		font-size: 15px;
		line-height: 1;
		font-weight: bold;
		padding: 16px;
	}
	.el-card__body {
		padding: 16px 0 0 16px;
	}
}
</style>
